<template>
<Modal v-model="modalCreate"  @on-ok="handleModalCreateOK" :styles="{top: '30px'}" width="600">
	<template #header>添加企业信息</template>
	<Form ref="form" :model="formData" :rules="ruleValidate" :label-width="90">
		<FormItem label="营业执照" prop="business_license">
			<Upload ref="upload1" :show-upload-list="false" :on-success="handleUpload1Success" 
			:format="['jpg','jpeg','png']" :max-size="20480" type="drag" 
			name="file" style="display: inline-block;width:90px;"  
			:action="uploadActionBusiness">
			    <div style="width: 90px;height:64px;line-height: 64px;">
			        <Icon type="ios-camera" size="24" v-if="formData.business_license==''"></Icon>
			        <img :src="formData.business_license" height="64" v-else>
			    </div>
			</Upload>
		</FormItem>
		<FormItem label="企业名称" prop="enterprise_name">
			<Input v-model="formData.enterprise_name"></Input>
		</FormItem>
		<FormItem label="负责人" prop="legal_representative">
			<Input v-model="formData.legal_representative"></Input>
		</FormItem>
		<FormItem label="联系电话" prop="phone">
			<Input v-model="formData.phone"></Input>
		</FormItem>
		<FormItem label="身份证号" prop="legal_cid">
			<Input v-model="formData.legal_cid"></Input>
		</FormItem>
		<FormItem label="信用码" prop="reg_num">
			<Input v-model="formData.reg_num"></Input>
		</FormItem>
		<FormItem label="地址" prop="regist_address">
			<Input v-model="formData.regist_address"></Input>
		</FormItem>
	</Form>
	<template #footer><Button type="primary" @click="handleModalCreateOK">确定</Button></template>
</Modal>
</template>

<script>
import config from '@/config'
export default{
	data(){
		return{
			modalCreate:false,
			formData:{
				business_license:''
			},
			ruleValidate:{
				enterprise_name: [{ required: true, message: '企业名称不能为空'}],
				legal_representative: [{ required: true, message: '负责人不能为空'}],
				phone: [{ required: true, message: '联系电话不能为空'}],
				legal_cid: [{ required: true, message: '身份证号不能为空'}],
				reg_num: [{ required: true, message: '信用码不能为空'}],
				regist_address: [{ required: true, message: '地址不能为空'}]
			}
		}
	},
	props: {
		to: {
			type: String,
			default: ''
		}
	},
	computed:{
		uploadActionBusiness(){
			return config.baseUrl+'tangyin/main/mainCase1UploadBusiness.action'
		}
	},
	methods:{
		open(){
			this.modalCreate=true
			this.$refs.form.resetFields()
		},
		handleModalCreateOK(){
			this.$refs.form.validate((valid) => {
				if (valid) {
					let data=this.formData
					this.$axios.post("mainCase1EnterpriseSave.action",data).then(res=>{
						this.$Message.success('保存成功')
						this.modalCreate=false
						this.$emit("loadData",data)
					})
				}
			})
		},
		handleUpload1Success(res, file, fileList){//营业执照上传成功
			this.formData.business_license=config.baseUrl+res.tarFile
			this.formData.legal_representative=res.legalPerson
			this.formData.enterprise_name=res.companyName
			this.formData.reg_num=res.creditCode
			this.formData.regist_address=res.businessAddress
		}
	}
}
</script>

<style>
</style>